Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime: minor bugs fixed in coreclr and libraries #97155

Merged
merged 9 commits into from
Jan 19, 2024
Merged

Conversation

kaybelev
Copy link
Contributor

@kaybelev kaybelev commented Jan 18, 2024

The bugs fixed are related to:
-situations where a pointer is dereferenced, but can only have NULL value, and so the operation of dereference can never be run without causing a runtime error;
-after some value is retrieved by as operator, the original value is checked for null instead of the new one.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

…cpp:262, may be NULL and is dereferenced at filetime.cpp:268>. The error was detected using the Svace analyzer maded by ISP RAS.
…d at process.cpp:2824 without checking for NULL, but it is usually checked for this function (11/12)>. The error was detected using the Svace analyzer maded by ISP RAS.
…on with possible null return value, is dereferenced in member access expression sectionRecord.HasLocationInput>. The error was detected using the Svace analyzer maded by ISP RAS.
…h AS-cast should be compared with null instead of method>. The error was detected using the Svace analyzer maded by ISP RAS.
@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Jan 18, 2024
@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jan 18, 2024
@kaybelev
Copy link
Contributor Author

@dotnet-policy-service agree

@@ -335,7 +335,7 @@ internal ConfigurationSection FindImmediateParentSection(ConfigurationSection se

string configKey = section.SectionInformation.SectionName;
SectionRecord sectionRecord = GetSectionRecord(configKey, false);
if (sectionRecord.HasLocationInputs)
if ((sectionRecord != null) && sectionRecord.HasLocationInputs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't actually fix a null reference exception. If sectionRecord could actually be null, this will cause the else block to be executed, which also immediately dereferences sectionRecord.

Unless there's a known repro for this causing a problem, let's revert this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stefan, to correct the error, I propose below in line 346 to change the condition to <if ((sectionRecord != null) && sectionRecord.HasIndirectLocationInputs)>. Stefan, judging by the results of the static analysis, the value returned by the function GetSectionRecord(...) in the library System.Configuration.ConfigurationManager code base should be checked for NULL (you can search (sectionRecord==null or sectionRecord!=null) by searching in the files MgmtConfigurationRecord.cs and BaseConfigurationRecord.cs). I suggest you fix it. It is not possible to check for an error in this case using a test, because it was detected using a static analysis tool.

Copy link
Contributor Author

@kaybelev kaybelev Jan 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit updated.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is searching for immediate parent section. I assume that the immediate parent section is expected to always exist and that's why there is no null check. Maybe we can add Debug.Assert instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, let's try, just explain what needs to be done for this.

@@ -263,6 +263,7 @@ BOOL PALAPI FileTimeToSystemTime( CONST FILETIME * lpFileTime,
#else /* HAVE_GMTIME_R */
UnixSystemTime = gmtime( &UnixFileTime );
#endif /* HAVE_GMTIME_R */
if (!UnixSystemTime) return FALSE;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!UnixSystemTime) return FALSE;
if (!UnixSystemTime)
{
ERROR( "gmtime failed.\n" );
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jan, thanks for the correction, we'll take it into account for the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit updated.

@kaybelev kaybelev requested a review from jkotas January 19, 2024 11:04
kaybelev and others added 2 commits January 19, 2024 14:48
…stem/Configuration/MgmtConfigurationRecord.cs

Co-authored-by: Jan Kotas <jkotas@microsoft.com>
…stem/Configuration/MgmtConfigurationRecord.cs

Co-authored-by: Jan Kotas <jkotas@microsoft.com>
Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@jkotas jkotas merged commit 43f2d94 into dotnet:main Jan 19, 2024
146 of 151 checks passed
@kaybelev
Copy link
Contributor Author

Thanks for the work you've done.

tmds pushed a commit to tmds/runtime that referenced this pull request Jan 23, 2024
* Fixed error: <Pointer, returned from function 'gmtime_r' at filetime.cpp:262, may be NULL and is dereferenced at filetime.cpp:268>. The error was detected using the Svace analyzer maded by ISP RAS.

* Fixed error: <Return value of a function 'PAL_wcsrchr' is dereferenced at process.cpp:2824 without checking for NULL, but it is usually checked for this function (11/12)>. The error was detected using the Svace analyzer maded by ISP RAS.

* Fixed error: <Value sectionRecord, which is result of method invocation with possible null return value, is dereferenced in member access expression sectionRecord.HasLocationInput>. The error was detected using the Svace analyzer maded by ISP RAS.

* Fixed error: <Maybe ecmaCandidateMethod, that created from method with AS-cast should be compared with null instead of method>. The error was detected using the Svace analyzer maded by ISP RAS.

* Update filetime.cpp

* Update process.cpp

* Update MgmtConfigurationRecord.cs

* Update src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/MgmtConfigurationRecord.cs

Co-authored-by: Jan Kotas <jkotas@microsoft.com>

* Update src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/MgmtConfigurationRecord.cs

Co-authored-by: Jan Kotas <jkotas@microsoft.com>

---------

Co-authored-by: Jan Kotas <jkotas@microsoft.com>
@github-actions github-actions bot locked and limited conversation to collaborators Feb 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
community-contribution Indicates that the PR has been added by a community member needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants